package cn.hnucm.searchesservice.utils;


import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * 访问路径：http://localhost:8085/swagger-ui.html#/
 * ip地址： 10.134.180.227     http://10.134.180.227:8081/swagger-ui.html#/
 */
@Configuration
@EnableSwagger2
public class Swagger2 {

    /* 注： 在不同的项目中都需要修改*/
    private static String packagePath = "cn.hnucm.searchesservice.controller";

    @Bean
    public Docket createRestApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())//调用apiInfo方法,创建一个ApiInfo实例,里面是展示在文档页面信息内容
                .select()
                .apis(RequestHandlerSelectors.basePackage(packagePath))
                .paths(PathSelectors.any())
                .build();
    }

    //构建 api文档的详细信息函数
    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                //页面标题
                .title("Spring Boot Swagger2 构建RESTful API")
                .termsOfServiceUrl("http://www.github.io/")
                .version("1.0")
                .description("API 描述")
                .build();
    }
}